package CustomizeProfile;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import CustomizeProfile.ProfileUpdater;
import com.sun.corba.se.pept.transport.ContactInfo;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Asus
 */
@WebServlet(name="ServletUpdateProfile", urlPatterns={"/ServletUpdateProfile"})
public class ServletUpdateProfile extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletUpdateProfile</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ServletUpdateProfile at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
            */
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String nama_perusahaan = request.getParameter("nama_perusahaan");
        //String alamat = request.getParameter("alamat");
        StringBuffer txtalamat = new StringBuffer(request.getParameter("alamat"));
        String alamat = txtalamat.toString();
        String telepon = request.getParameter("telepon");
        String email = request.getParameter("email");
        String logo = request.getParameter("logo");
        String welcome_msg = request.getParameter("welcome_msg");
        //String kontak_tambahan = request.getParameter("kontak_tambahan");
        StringBuffer txtkontaktambahan = new StringBuffer(request.getParameter("kontak_tambahan"));
        String kontak_tambahan = txtkontaktambahan.toString();
        String jml_diskon_STR = request.getParameter("jml_diskon");
        String syarat_diskon_STR = request.getParameter("syarat_diskon");

        float jml_diskon = Float.valueOf(jml_diskon_STR);
        int syarat_diskon = Integer.valueOf(syarat_diskon_STR);

        ProfileUpdater conn = new ProfileUpdater();
        conn.UpdateProfil(nama_perusahaan, alamat, telepon, email, logo, welcome_msg, kontak_tambahan, jml_diskon, syarat_diskon);
        
        response.setContentType("text/html");

        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title> Updating Profile</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("Profile successfully updated<br/>");
        out.println("nama perusahaan ="+nama_perusahaan+"<br/>");
        out.println("alamat ="+alamat+"<br/>");
        out.println("telepon ="+telepon+"<br/>");
        out.println("email ="+email+"<br/>");
        out.println("logo ="+logo+"<br/>");
        out.println("welcome message ="+welcome_msg+"<br/>");
        out.println("kontak tambahan ="+kontak_tambahan+"<br/>");
        out.println("jumlah diskon ="+jml_diskon+"<br/>");
        out.println("syarat diskon ="+syarat_diskon+"<br/>");
        out.println("Profile successfully updated<br/>");
        out.println("</body>");
        out.println("<a href='http://localhost:8080/SMARTravel-war/CustomizeInfo.jsp'>"+"Click here to go back to input page "+"</a>");
        out.println("</html>");
        out.close();

        processRequest(request, response);
        
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
